import { _decorator, Component, EditBox, game, Input, input, Label, Node, Renderable2D, RenderRoot2D } from 'cc';
import { gameManger } from './gameManger';
import { bulletController } from './bulletController';
import { bloodController } from './bloodController';
const { ccclass, property } = _decorator;

@ccclass('dialogController')
export class dialogController extends Component {
    @property(Node) gameManger: Node
    // @property(Node) nameNode: Label
    @property(EditBox) editBox: EditBox = null
    @property(Node) nameNode: Node = null
    private index = 1
    private content = [
        "你好，我是你的梦魇",
        "你要给我起个名字吗？",
        "准备好了么？",
        "让我们开始吧！"
    ]
    private label: Node = null
    private headName:string = ""
    start() {
    }

    update(deltaTime: number) {
    }

    updataContent() {
        if (this.index < this.content.length) {
            this.label.getComponent(Label).string = this.content[this.index]
            if(this.index == 1){
                this.node.getChildByPath("SpriteSplash/EditBox").active = true
            }else{
                this.node.getChildByPath("SpriteSplash/EditBox").active = false
            }
            this.index++
        } else {
            this.node.active = false
            this.label.off(Input.EventType.TOUCH_END, this.updataContent, this)
            this.index = 1
            this.gameManger.getComponent(gameManger).dialogEnd()
        }
    }

    showDialog() {
        this.label = this.node.getChildByPath("SpriteSplash/Label")
        this.label.on(Input.EventType.TOUCH_END, this.updataContent, this)
        this.label.getComponent(Label).string = this.content[0]
        this.node.active = true
    }
    setShowDialog(string: string) {
        this.label = this.node.getChildByPath("SpriteSplash/Label")
        this.label.on(Input.EventType.TOUCH_END, this.updataContent, this)
        this.label.getComponent(Label).string = string
        this.index = this.content.length
        this.node.active = true
    }
    hiddenDialog() {
        this.node.active = false
        this.label.off(Input.EventType.TOUCH_END, this.updataContent, this)
        this.index = 1
        this.gameManger.getComponent(gameManger).dialogEnd()
    }

    setDevilName(){
        let label = this.nameNode.addComponent(Label)
        label.string = this.editBox.string
        label.fontSize = 30
        this.updataContent()
    }
    cancel(){
        this.updataContent()
    }
}


